class WikiPage < ActiveRecord::Base
  #acts_as_taggable_on :categories
  
  # index the first and last names 
  #acts_as_ferret :store_class_name => true, :fields => {:title => {:store => :yes},
  #                           :body => {:store => :no}}
  
  validates_uniqueness_of     :title
  
  has_many :revisions, :order => "created_on DESC", :class_name => "WikiRevision", :dependent => :destroy
  
  # before create, make title safe for url
  #before_create :underscore_title
  #before_validation :underscore_title
  
  # give a wikized version of the body of this page
  def body
    revisions.first.wikized_body
  end
  
  # returns the raw markup and wiki links of the first revision
  def raw_body
    revisions.first.body
  end
  
  # returns the most recent editor of this page
  def editor
    revisions.first.editor
  end
  
  def edited_on
    revisions.first.created_on
  end
  
  # convert the title into something safe for the url
  def slug
    self.title.gsub(" ","_")
  end
   
end
